<?php
require_once("vcl/vcl.inc.php");
require_once("lib/db_connection.php");
//Includes
use_unit("platinumgrid/jtplatinumgrid.inc.php");
use_unit("components4phpfull/jtsitetheme.inc.php");
use_unit("forms.inc.php");
use_unit("extctrls.inc.php");
use_unit("stdctrls.inc.php");

//Class definition
class AMPS_Reminders extends Page
{
       public $Image4 = null;
       public $hiddenVeh = null;
       public $JTPlatinumVehicleList = null;
       public $JTReminderList = null;
       public $JTSiteTheme1 = null;


       function AMPS_RemindersCreate($sender, $params)
       {

       $veh_id = $_GET['veh'];
       $this->hiddenVeh->setValue($veh_id);

       $query_vehicle = mysql_query("select * from vehicle_tbl where company_id='".$_SESSION['company_id']."'");
       $temp_vehicle = mysql_num_rows($query_vehicle);

       if($temp_vehicle!=0)
       {
        if($veh_id==null || $veh_id=='')
        {
        $comp_id = $_SESSION['company_id'];
        $query1 = "select * from vehicle_tbl where company_id='".$comp_id."' LIMIT 1";
        $result = mysql_query($query1)or die(mysql_error());
        $row_veh = mysql_fetch_array($result);
        $veh = $row_veh['vehicle_id'];
        //die($query1);
        redirect('PopReminder.php?veh='.$veh);
        }
       }
       }


       function JTPlatinumVehicleListShow($sender, $params)
       {
        $comp_id = $_SESSION['company_id'];
        $query_veh = "select * from vehicle_tbl where company_id='".$comp_id."'";
        $result_veh = mysql_query($query_veh)or die(mysql_error());

        $arr = array();
        while($row_veh = mysql_fetch_array($result_veh))
          {
            $vehicle_id = $row_veh['vehicle_id'];
            $veh_style = $row_veh['style_name'];

            if($this->hiddenVeh->getValue()==$vehicle_id)
            $radio = "<a href=PopReminder.php?veh=".$vehicle_id."><img src='image/radio_select.png' border></a>";
            else
            $radio = "<a href=PopReminder.php?veh=".$vehicle_id."><img src='image/radio.png' border></a>";
            //$VIN = "<a href=vehicle_edit.php?veh=".$vehicle_id.">".$row['VIN']."</a>";


            $arr[] = array(
                        'Plate Num' => $radio.'  '.$row_veh['veh_num'],
                        'Year' => $row_veh['year'],
                        'Make' => $row_veh['manufacturer_name'],
                        'Model' => $row_veh['model_name']
                        );


          }





            $this->JTPlatinumVehicleList->setCellData($arr);


       }


       function JTReminderListShow($sender, $params)
       {

       $this->JTReminderList->Style=WHITE;
       /*$query_due = "select * from veh_reminder_tbl where company_id='".$_SESSION['company_id']."' and vehicle_id='".$this->hiddenVeh->getValue()."'and status='Due'";
       $result_due = mysql_query($query_due)or die(mysql_error());

        $arr = array();
        while($row_due = mysql_fetch_array($result_due))
          {
            $vehicle_id = $row_due['vehicle_id'];


            $arr[] = array(
                        'Due at(miles/hrs)' => $row_due['due_hours'],
                        'Due by' => $row_due['due_date'],
                        'Type' => $row_due['type'],
                        'Reminder Description' => $row_due['description'],
                        );


          } */

        $query_check = "select * from veh_reminder_tbl where company_id='".$_SESSION['company_id']."'and vehicle_id='".$this->hiddenVeh->getValue()."'";
        $result_check = mysql_query($query_check)or die(mysql_error());

        $query_od = "select * from vehicle_tbl where company_id='".$_SESSION['company_id']."' and vehicle_id='".$this->hiddenVeh->getValue()."'";
        $result_od = mysql_query($query_od)or die(mysql_error());
        $row_od = mysql_fetch_array($result_od);

        while($row_check = mysql_fetch_array($result_check))
          {

            $vehicle_id = $row_check['vehicle_id'];
            $due_date = $row_check['due_date'];
            $curr_date = date("Y-m-d");
            $odometer = $row_check['due_hours'];
            $curr_od = $row_od['curr_tracking_value'];

            if($curr_date>=$due_date || $curr_od>=$odometer)
            {
               $arr[] = array(
               'Due at(miles/hrs)' => $row_check['due_hours'],
               'Due by' => $row_check['due_date'],
               'Type' => $row_check['type'],
               'Reminder Description' => $row_check['description'],
               );
            }




          }

            $this->JTReminderList->setCellData($arr);


       }

}

global $application;

global $AMPS_Reminders;

//Creates the form
$AMPS_Reminders=new AMPS_Reminders($application);

//Read from resource file
$AMPS_Reminders->loadResource(__FILE__);

//Shows the form
$AMPS_Reminders->show();

?>